package com.erp.client.widget;

import com.extjs.gxt.ui.client.event.ButtonEvent;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.widget.Dialog;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.button.StatusButtonBar;
import com.extjs.gxt.ui.client.widget.form.FormPanel;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.erp.client.DAO.*;
import com.erp.client.MessAge.myMesswindow;
import com.erp.client.systemEntryPoint;
import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
import com.extjs.gxt.ui.client.Style.Scroll;
import com.extjs.gxt.ui.client.data.BeanModel;
import com.extjs.gxt.ui.client.widget.Info;
import com.extjs.gxt.ui.client.widget.Window;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
import com.extjs.gxt.ui.client.widget.layout.FlowLayout;
import com.extjs.gxt.ui.client.widget.layout.FormData;
import com.extjs.gxt.ui.client.widget.layout.FormLayout;
import com.google.gwt.user.client.ui.Panel;

public class myLoginDialog extends Dialog {

    protected Button reset;
    protected Button save;
    protected FormPanel form;
    protected StatusButtonBar buttonBar;
    protected ServerUserBaseAsync customerService;
    protected BeanModel customerModel;
    final private myMesswindow messdisp = new myMesswindow();

    public myLoginDialog() {
        final Window w = new Window();
        w.setPlain(true);
        w.setSize(300, -1);
        w.setHeading("登录窗口");
        w.setLayout(new FitLayout());

        final FormPanel panel = new FormPanel();
        panel.setBorders(false);
        panel.setBodyBorder(false);
        panel.setLabelWidth(60);
        panel.setPadding(5);
        panel.setHeaderVisible(false);
        panel.setButtonAlign(HorizontalAlignment.CENTER);


        final TextField<String> loginId = new TextField<String>();
        //loginId.setName("loginId");
        loginId.setFieldLabel(" 用户名 ");
        loginId.setAllowBlank(false);
        loginId.setMinLength(2);
        loginId.setMaxLength(10);
        loginId.setEmptyText("请输入用户名");
        loginId.setMessageTarget("请输入用户名");
        panel.add(loginId, new FormData("100%"));

        final TextField<String> password = new TextField<String>();
        //password.setName("password");
        password.setFieldLabel(" 密 码 ");
        password.setAllowBlank(false);
        password.setMinLength(4);
        password.setMaxLength(10);
        password.setEmptyText("请输入密码");
        password.setMessageTarget("请输入密码");
        panel.add(password, new FormData("100%"));



        buttonBar = new StatusButtonBar();
        //setButtonBar(buttonBar);
        reset = new Button("重置");
        reset.addSelectionListener(new SelectionListener<ButtonEvent>() {

            public void componentSelected(ButtonEvent ce) {
                //myUpdataRzlogDialog.this.hide();
                Info.display("Event", "The '重置' tool was clicked");
                panel.reset();

            }
        });

        save = new Button("保存");

        save.addSelectionListener(new SelectionListener<ButtonEvent>() {

            public void componentSelected(ButtonEvent ce) {
                Info.display("Event", "The '保存' tool was clicked");
                UserBaseInf ub = new UserBaseInf();
                ub.setLoginId(loginId.getValue().toString());
                ub.setPassword(password.getValue().toString());
                Info.display("Event", ub.getLoginId().toString());
                              AsyncCallback callback = new AsyncCallback() {

                    public void onSuccess(Object result) {
                        buttonBar.enable();
                        messdisp.myMessWindow("系统提示", "登录成功！");                        
                        close();
                       
                    }

                    public void onFailure(Throwable caught) {
                        Info.display("server", "server连接失败");
                        buttonBar.enable();
                    }
                };
                ServerUserBaseGetService.getService().UserRightsLogin(ub, callback);
               
            }
        });

        buttonBar.add(save);
        buttonBar.add(reset);

        w.setButtonBar(buttonBar);
        w.add(panel);
        w.show();
    }
}
